﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Guoc.BigMall.Web.Services
{
    public class ResultModel
    {
        private ResultModel() { }

        private static ResultModel CreateModel(int code, bool success, string message, object data)
        {
            return new ResultModel()
            {
                Code = code,
                Success = success,
                Message = message,
                Data = data
            };
        }

        static string _SuccessMessage = "success";

        public int Code { get; private set; }
        public bool Success { get; private set; }
        public string Message { get; private set; }

        public object Data { get; private set; }



        public static ResultModel Ok()
        {
            return CreateModel(200, true, _SuccessMessage, new object());
        }

        public static ResultModel Ok(object data)
        {
            return CreateModel(200, true, _SuccessMessage, data);
        }
        /// <summary>
        ///  500  内部错误
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static ResultModel Error()
        {
            return Error("500 服务器内部错误！");
        }
        /// <summary>
        ///  500  内部错误
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static ResultModel Error(string errorMessage)
        {
            return CreateModel(500, false, errorMessage, new object());
        }
        /// <summary>
        ///  401 未授权
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static ResultModel Unauthorized()
        {
            return Unauthorized("401 请求用户未授权！");
        }
        /// <summary>
        ///  401 未授权
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static ResultModel Unauthorized(string errorMessage)
        {
            return CreateModel(401, false, errorMessage, new object());
        }
    }
}
